<?
/*
 * JuickDiff PHP
 * index.php by Skobkin.ru
 * http://juick.com/skobkin-ru
*/
include_once("juick.php");

$user = $_GET["user"];
if (!ereg('^[^./][^/]*$', $user)) // Scan username for security
     die('bad filename');

echo "User: ".$user."<br><br>";
$subfile = "users/$user.txt";
$user = "http://juick.com/".$user."/readers";

$code = GetHTML($user);
$nowfriends = ParseFriends($code);

if (file_exists($subfile))
{
    $lastfriends = file($subfile); // GetLines($subfile);
    // Let's check the difference :)
    $diff = Diff($nowfriends, $lastfriends);
    echo "Diff:
        <br><textarea name=content rows=20 cols=100>
        ".implode("\r\n", $diff)."
        </textarea>";
}else
{
    echo "Your first subscribers check<br>";
}

// Write all you subscribers to file
// if(!is_writable($subfile)) die("Subscibers file is not writable!"); // Check for write
$f = fopen($subfile, "w"); // Opening file for writing
for ($i=0; $i < count($nowfriends); $i++)
{
    fwrite($f, $nowfriends[$i]."\r"); // Write each element to new line
}
fclose($f);
echo "<br>Index file saved.";


?>